var newApp = new Vue({
	el: '#main',
	data: {
		info: null,
		updable: false,
	},
	created: function() {
		this.init();
	},
	methods: {
		init: function() {
			this.info = util.localGet("myinfo");
			var updable = util.local("myinfoUpdate");
			if(updable) {
				this.updable = true;
			}
			console.info(this.updable);
		},
		imgUploadClick: function(){
			uploadFileClick();
		},
		imgChange: function(event) {
			var temp = util.localGet("myinfo");
			var f = event.target.files[0];
			var formData = new FormData();
			formData.append("file",f);
			var that = this;
			util.upload("https://www.maksdu.com/app/upload/headpic", formData, function(result) {
				//console.info(result);
				if(result) {
					that.info.headpic = result;
					temp.headpic = result;
					util.localSet("myinfo",temp);
					window.localStorage.setItem("myinfoUpdate",true);
				}
			});
		},
		saveInfo: function() {
			var that = this;
			var info = window.localStorage.getItem('myinfo');
			saveInformation(info ,function(result){
				util.localSet("myinfo", result.userinfo);
				window.localStorage.setItem("myinfoUpdate",false);
				window.location.replace("https://www.maksdu.com/content/personal/");
			});
		}
	}
});


function uploadFileClick() {
	$("#file").click();
}

function saveInformation(info, callback) {
	$.ajax({
        url:'https://www.maksdu.com/app/userinfo/add',
        type: 'post',
        data: info,
        contentType : 'application/json',
        dataType : 'json',
        headers: {
            request_access_token: window.localStorage.getItem('token')
        },
        success: function(data) {
           callback(data);
        }
    })
}